/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package facade;

import entity.User2;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author lab1
 */
@Stateless
public class User2Facade extends AbstractFacade<User2> implements User2FacadeRemote {

    @PersistenceContext(unitName = "SHOPPINGCART2-ejbPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public User2Facade() {
        super(User2.class);
    }
    //phuong thuc login cua nguoi dung

    public boolean login(User2 us) {
        Query query = em.createQuery("select count(o) from User2 o "
                + "where o.userName = :username and o.password =:password");
        query.setParameter("username", us.getUserName());
        query.setParameter("password", us.getPassword());
        long count = 0;
        Object result = (Object) query.getSingleResult();
        count = (Long) result;
        if (count == 1) {
            return true;
        }
        return false;
    }
}
